package ext.sim;

import context.render.vertexdata.VertexData;
import ext.render.RenderSphere;
import ext.sim.contact.detect.TreeSphere;
import java.util.ArrayList;
import math.mat3;
import math.region.Sphere3;
import math.vec3;

public class BodySphere extends Body
{
    
    
    public double mRadius;
    
    
    public BodySphere(double aRadius)
    {
        super();
        
        this.mRadius = aRadius;
        
        this.calcInertiaTensor();
        
        ArrayList<Sphere3> spheres = new ArrayList<>();
        spheres.add(new Sphere3(vec3.ZERO, aRadius));
        this.mTreeSphere = new TreeSphere(vec3.ZERO, spheres);
    }
    
    
    public final void calcInertiaTensor()
    {
        // Compute the inertia tensor in body-space.
        double massFac = 0.4 * this.mMass;
        double sqR = this.mRadius * this.mRadius;
        this.mIbody.set(mat3.ZERO);
        this.mIbody.m[0] = massFac * sqR; // Diagonal entries.
        this.mIbody.m[4] = massFac * sqR;
        this.mIbody.m[8] = massFac * sqR;
        
        // Compute the inverse of the above matrix--easy because it's a diagonal matrix!
        this.mInvIbody.m[0] = 1.0 / this.mIbody.m[0];
        this.mInvIbody.m[4] = 1.0 / this.mIbody.m[4];
        this.mInvIbody.m[8] = 1.0 / this.mIbody.m[8];
    }
    
    public void render(VertexData aVertexData)
    {
        RenderSphere.render(aVertexData, this.mX, this.mR, this.mRadius);
    }
    
    
    
}
